package com.surfilter.massdata.spark.model;

import java.io.Serializable;
import java.util.Arrays;

/**
 * @author lhfcws
 * @time 14-2-16.
 */
public class StructIP implements Comparable<StructIP>,Serializable{
	
	private static final long serialVersionUID = 1L;
	
	private String[] fields = new String[DnsStatConsts.IPExField.size()];
    private long beginIPValue = 0;
    private long endIPValue = 0;

    public StructIP(long beginIPValue, long endIPValue) {
        Arrays.fill(fields, null);
        this.beginIPValue = beginIPValue;
        this.endIPValue = endIPValue;
    }

    public StructIP(long beginIPValue, long endIPValue, String[] args) {
        if (fields.length == args.length) {
            fields = args.clone();
            this.beginIPValue = beginIPValue;
            this.endIPValue = endIPValue;
        } else
            Arrays.fill(fields, null);
    }

    public void set(int i, String value) {
        fields[i] = value;
    }

    public String get(int i) {
        return fields[i];
    }

    public boolean inProvince() {
        return true;
    }

    @Override
    public int compareTo(StructIP structIP) {
        return this.get(DnsStatConsts.IPExField.IP).compareTo(structIP.get(DnsStatConsts.IPExField.IP));
    }

    public String toString() {
        return Arrays.toString(fields);
    }

    public long getBeginIPValue() {
        return beginIPValue;
    }

    public long getEndIPValue() {
        return endIPValue;
    }

    public String[] getFields() {
        return fields;
    }
}

